package iotwisp.base.cqrs;

import java.io.Serializable;
import java.util.List;

import javax.validation.constraints.NotBlank;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 基础查询类 名词解释：query object 简称 qo
 *
 * @author
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class BaseQO<T> implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 别名，在进行关联查询时设置关联对象的别名
	 */
	private String alias;

	/**
	 * 需要筛选出来的实体字段名，可以带“.”进入组件对象的下一级属性。用于非select *查询
	 */
	private String[] projectionProperties;
	private String[] projectionDistinctProperties;

	// ------------------延迟加载条件------------------
	// ------------------排序条件------------------
	// ------------------属性条件------------------
	/**
	 * 实体ID
	 */
	private T id;
	/**
	 * 实体ID集合，设置后会进行in查询
	 */
	private List<T> ids;

	// ------------------不包含的属性条件------------------
	/**
	 * 不包含的ID集合，设置后会进行not in查询
	 */
	private T[] idNotIn;

	// ------------------状态类条件------------------

	// 分页条件
	private Integer pageNo = 1;

	private Integer pageSize = 10;

	private Integer offset = 0;

	private Integer limit = 100;

	/**
	 * 是否忽略QO上的注解，当注解中的条件解析方式不适合自己的查询需要时关闭，进行手工条件组装
	 */
	private Boolean ignoreQueryAnnotation = false;

	/**
	 * 是否关联抓取了集合
	 */
	private Boolean batchResult = false;

	/**
	 * 查询结果类型
	 */
	@NotBlank(message = "resultType不能为空")
	private String resultType;

	public final static String RESULT_TYPE_COUNT = "count";
	public final static String RESULT_TYPE_UNIQUE = "unique";
	public final static String RESULT_TYPE_LIST = "list";
	public final static String RESULT_TYPE_PAGINATION = "pagination";
    public final static String RESULT_TYPE_TREE = "tree";

	public final static Integer ORDER_ASC = 1;
	public final static Integer ORDER_DESC = -1;

	/**
	 * 悲观读锁
	 */
	private boolean readLock;

	/**
	 * 悲观写锁
	 */
	private boolean writeLock;

	/**
	 * 自增别名
	 */
	private Integer aliasNum = 0;

	/**
	 * 数据使用场景，用于简化查询条件传参
	 */
	private String dataUseScene = "default";

	/**
	 * 分页查询时是否要先count
	 */
	private Boolean selectCount = true;

	private Boolean openNewSession = false;

	private String maxProperty;
	private String maxValueProperty;

	private String minProperty;
	private String minValueProperty;
}